package com.handinglian.ai.system.controller;

import com.apidoc.annotation.Api;
import com.handinglian.ai.common.dto.ResultData;
import com.handinglian.ai.system.dto.MenuDto;
import com.handinglian.ai.system.dto.RoleDto;
import com.handinglian.ai.system.param.RoleCreateParam;
import com.handinglian.ai.system.param.RoleUpdateParam;
import com.handinglian.ai.system.service.MenuService;
import com.handinglian.ai.system.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("角色权限")
@RestController
@Slf4j
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @Autowired
    private MenuService menuService;

    /**
     * 创建角色
     */
    @PostMapping("/create")
    public ResultData create(@RequestBody RoleCreateParam roleCreateParam){
        int amount = roleService.create(roleCreateParam);
        return ResultData.success(amount);
    }

    /**
     * 删除角色
     */
    @DeleteMapping(value = "/delete")
    public ResultData delete(Integer id) {
        int amount = roleService.delete(id);
        return ResultData.success(amount);
    }

    /**
     * 更新角色
     */
    @PutMapping(value = "/update")
    public ResultData update(@RequestBody RoleUpdateParam roleUpdateParam) {
        int amount = roleService.update(roleUpdateParam);
        return ResultData.success(amount);
    }

    /**
     * 获取角色列表
     */
    @GetMapping("/list")
    public ResultData<RoleDto> list() {
        List<RoleDto> roleList = roleService.list();
        return ResultData.success(roleList);
    }

    /**
     * 获取菜单权限列表
     */
    @GetMapping("/listMenu")
    public ResultData<MenuDto> listMenu() {
        List<MenuDto> menuDtos = menuService.list();
        return ResultData.success(menuDtos);
    }

    /**
     * 获取角色权限
     */
    @GetMapping("/getDetail")
    public ResultData<RoleDto> getDetail(Integer id) {
        RoleDto roleDto = roleService.getDetail(id);
        return ResultData.success(roleDto);
    }
}
